package com.along.framework.web;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 分页action
 * @author Administrator
 *
 */
public class PageAction extends BaseAction {

	private int currentPage = 1;// 当前页码

	private int totalItem = 0;// // 总的记录数

	private int perPage = 10;//每页显示的记录数目

	private int startRow = 0;

	String queryWhere;

	public String getQueryWhere() {
		return queryWhere;
	}

	@SuppressWarnings("unchecked")
	public void setQueryWhere(Map queryWhere) {
		StringBuffer where = new StringBuffer();
		String key = "";
		int index = 1;
		Set set = queryWhere.keySet();
		for (Iterator iterator = set.iterator(); iterator.hasNext();) {
			key = (String) iterator.next();
			where.append(key).append("=").append(queryWhere.get(key));
			if (index != set.size()) {
				where.append("&");
			}
			index++;
		}
		this.queryWhere = where.toString();
	}

	/**
	 * 当前页码
	 * */
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;

	}
	public void setCurrentPage(String currentPage) {
		this.currentPage = Integer.parseInt(currentPage);
	}

	/**
	 *总的记录数
	 * */
	public int getTotalItem() {
		return totalItem;
	}

	public void setTotalItem(int totalItem) {
		this.totalItem = totalItem;
	}

	/**
	 *每页显示的记录数目
	 * */
	public int getPerPage() {
		return perPage;
	}

	public void setPerPage(int perPage){//,Page page) {
		this.perPage = perPage;
	//	page.setEveryPage(perPage);
	}

	public int getStartRow() {

		return startRow = currentPage == 1 ? startRow : perPage
				* (currentPage - 1);
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	

}
